home *** CD-ROM | disk | FTP | other *** search
/ BMUG PD-ROM A / PD-ROM A.iso / Programming / Programming Help / MacsBug / More Macsbug < prev   
Encoding:
Text File  |  1992-01-05  |  38.3 KB  |  1,298 lines  |  [TEXT/EDIT]

  1. MacsBug Documentation
  2.  
  3.  
  4. MacsBug is the Macintosh 68000 Debugger.  This chapter describes the theory and operation of 
  5. MacsBug.  It also describes the syntax of commands accepted by MacsBug.
  6.  
  7.  
  8.  
  9.     Contents:
  10.  
  11.  
  12.         1    About MacsBug
  13.  
  14.         2    Installing MacsBug
  15.  
  16.         2    Theory of Operation - A Technical Aside
  17.  
  18.         4    Using MacsBug
  19.  
  20.         5    The MacsBug Command Language
  21.  
  22.                 Numbers
  23.  
  24.                 Strings
  25.  
  26.                 Symbols
  27.  
  28.                 Expressions
  29.  
  30.                 Commands
  31.  
  32.         6    General Commands
  33.  
  34.         7    Memory Commands
  35.  
  36.         8    Break Commands
  37.  
  38.         11    A-Trap Commands
  39.  
  40.         13    Heap Zone Commands
  41.  
  42.         15    Disassembler Commands
  43.  
  44.  
  45.  
  46. Note:  This chapter is specific to MacsBug 5.1 for Macintosh.  Some information does not apply to 
  47. earlier versions of MacsBug, which had different features or ran on different machines, such as the 
  48. Lisa.  
  49.  
  50.  
  51.  
  52. About MacsBug
  53.  
  54.  
  55. MacsBug is a line-oriented single-Macintosh debugger.  It resides in RAM along with the 
  56. application being debugged.  The capabilities of MacsBug include:
  57.  
  58.  
  59.     •  the ability to display and set memory and registers
  60.  
  61.     •  the ability to disassemble memory
  62.  
  63.     •  stepping and tracing through both RAM and ROM
  64.  
  65.     •  monitoring of system traps
  66.  
  67.     •  display and checking of the system and application heaps
  68.  
  69.  
  70. MacsBug obtains control when certain 68000 exceptions occur.  You can then examine memory, 
  71. trace through the application, or set up break conditions and execute the application until those 
  72. conditions occur.
  73.  
  74.  
  75. MacsBug 5.1 works with the following hardware configurations:
  76.  
  77.  
  78.     •  512K to 4 MB of RAM 
  79.  
  80.     •  64K Macintosh or 128K Macintosh Plus ROMs
  81.  
  82.     •  Motorola 68000 or 68020 processors
  83.  
  84.     •  Motorola 68881 floating-point coprocessor
  85.  
  86.  
  87. MacsBug 5.1 does not work on the Macintosh XL; if it accidentally finds its way onto a Macintosh 
  88. XL, it simply will not install itself.  Macintosh XL users should use MacXLBug.
  89.  
  90.  
  91.  
  92. Installing MacsBug
  93.  
  94.  
  95. MacsBug is not a normal Macintosh application.  Instead, MacsBug installs itself once at boot time 
  96. and remains active until shutdown.  This occurs if the following conditions are met:
  97.  
  98.     
  99.  
  100.     1)    MacsBug exists and is named exactly "MacsBug".  (An alternate name can be used by     
  101.     editing the boot blocks debugger name field with a standard utility like FEdit.)
  102.  
  103.     2)    It is on a startup (bootable) disk.
  104.  
  105.     3)    Is is in the current System Folder.  (This is only a requirement on HFS volumes. The         
  106. system folder is, by definition, the folder which contains a system file named "System"         
  107. and the system file named "Finder". )
  108.  
  109.  
  110. At the completion of a successful installation, the message “MacsBug installed” is displayed right 
  111. below the “Welcome to Macintosh” message.  The startup application is then launched as usual.
  112.  
  113.  
  114. The only way to remove an active copy of MacsBug is to reboot.  To override the installation of 
  115. MacsBug on a one time basis, hold the mouse button down during boot and MacsBug will not be 
  116. installed.  To permanently override the installation of MacsBug simply rename it to a different name 
  117. or remove it completely from the disk.   
  118.  
  119.   
  120.  
  121. Using HFS with the 64K ROM: If you have MacsBug on a Hard Disk 20 (HFS) boot disk on a 
  122. machine with the original 64K ROM, there is a seeming conflict with the above mouse-down 
  123. commands, because holding the mouse button down at boot also forces Macintosh to launch off of 
  124. the floppy disk rather than switch-launching to the Hard Disk 20.  However, a skillful mouser can 
  125. accomplish either command simply by knowing that MacsBug is installed first, right after the 
  126. “Welcome to Macintosh” hello message, and that the HFS code looks for a mouse-down only after 
  127. the “MacsBug installed” message.
  128.  
  129.  
  130. Theory of Operation — A Technical Aside
  131.  
  132.  
  133. Note:  Most people can skip this section.  It is not essential in order to use MacsBug but is provided 
  134. as important information to those who are interested in implementing a debugger to be used with 
  135. Macintosh.  It also provides a better background as to how MacsBug really works.
  136.  
  137.  
  138. The state of the world when MacsBug is about to be loaded is fairly complete.  The interrupt 
  139. system, memory manager, and ROM based I/O drivers have already been initialized by the ROM 
  140. boot code.  The boot code initializes the event manager, the font manager, the resource manager, 
  141. and the file system.  (Although the Toolbox is initialized at this point, MacsBug does not use the 
  142. Toolbox.)  The 'DSAT' table is loaded in and the string "Welcome To Macintosh" contained therein 
  143. is displayed.
  144.  
  145.  
  146. Next the loading process of MacsBug takes place as follows:  First the boot blocks code reserves 
  147. some space (1024 bytes) for MacsBug's own global variables.  Then this code proceeds to look for 
  148. the file specified in the boot blocks as described above.  If the file is not found (either due to an 
  149. improper location in an HFS volume or simply because the file is not on the boot volume) then the 
  150. global space is deallocated and the boot process continues normally without installing a debugger.
  151.  
  152.  
  153. If MacsBug is found, the data fork (not resource fork!) of the file is then loaded onto the current 
  154. stack which is located right under the main screen buffer in memory.  
  155.  
  156.  
  157. Historical Note:  For reasons related to the original Lisa Workshop, the first block (512 bytes) of 
  158. the MacsBug data fork is stripped off during this loading process.  In MacsBug 5.0 and later this 
  159. first block is used simply for version info about the file, as it does not take up any RAM.
  160.  
  161.  
  162. Then the boot code JSRs to MacsBug itself.  MacsBug begins its installation process by checking 
  163. to see if the mouse button is down.  If it is, MacsBug aborts the installation and lets the boot 
  164. process continue without installing itself.  If the button is not down, MacsBug determines which 
  165. kind of machine and microprocessor it is running on and configures itself accordingly.
  166.  
  167.  
  168. When installed, MacsBug puts pointers to itself in many of the hardware exception vectors in 
  169. addresses $0000 0000 through $0000 00FF.  It then remains dormant until one of “its” exceptions 
  170. occurs.  The following list of exceptions to which MacsBug responds are each numbered one 
  171. greater than the corresponding Macintosh System Error numbers.
  172.  
  173.  
  174.     Exception #            Assignment
  175.  
  176.  
  177.         2        Bus Error (rarely seen on Macintosh)
  178.  
  179.         3        Address Error (not aligned to a word boundary)
  180.  
  181.         4        Illegal Instruction (bit pattern not recognized)
  182.  
  183.         5        Zero Divide
  184.  
  185.         6        CHK Instruction (array index out of bounds)
  186.  
  187.         7        TRAPV Instruction (overflow)
  188.  
  189.         9        Trace (used to single step in MacsBug)
  190.  
  191.         10        Line 1010 Emulator (The A-trap handler for all Toolbox traps)
  192.  
  193.         11        Line 1111 Emulator (68xxx co-processor trap interface)
  194.  
  195.         28        Level 4 Interrupts
  196.  
  197.         29        Level 5 Interrupts
  198.  
  199.         30        Level 6 Interrupts
  200.  
  201.         31        Level 7 Interrupts
  202.  
  203.         47        Trap $F Instruction (Used for setting programmer breaks)
  204.  
  205.  
  206.  
  207. 68000 exception processing is described in the Motorola 68000 Programmer’s Reference Manual.  
  208.  
  209.  
  210. Any time an A-Trap or other exception listed above occurs, MacsBug intercepts the trap and can 
  211. thus stop or display the current state of the machine.  Single stepping through 68000 instructions is 
  212. possible because the Trace bit in the status register of the microprocessor can be set by MacsBug.
  213.  
  214.  
  215. During installation MacsBug obtains further memory from below the main screen buffer for use as 
  216. its own screen memory.  (MacsBug obtains memory from the same general area in RAM as RAM 
  217. disks and caching utilities.  It is based on the location of BufPtr, a Macintosh global variable.)  
  218. MacsBug 5.1 offers a full screen display with 40 lines saved.  This display uses about 20K of 
  219. memory.
  220.  
  221.  
  222. The total RAM memory requirement of MacsBug 5.1 is approximately as follows : 
  223.  
  224.  
  225.     Global space........1 KB
  226.  
  227.     Screen space.......20 KB
  228.  
  229.     Code space.........22 KB
  230.  
  231.              TOTAL:    43 KB
  232.  
  233.  
  234. MacsBug thus may not work with some memory-intensive applications on a 512K Macintosh.  
  235. Two solutions are possible:  
  236.  
  237.     
  238.  
  239.     1)     Remove MacsBug to free up about 43K of RAM
  240.  
  241.     2)    Add additional RAM via the Macintosh Plus Logic Board Upgrade or compatible third     
  242. party hardware upgrade to 1 MB of RAM or more.
  243.  
  244.  
  245. At the successful completion of the installation process an alert is posted below the "Welcome To 
  246. Macintosh" screen saying "MacsBug installed".  The boot process then continues by loading INIT 
  247. resources from the System file.   
  248.  
  249.  
  250. Technical Note:  The boot code looks for  INITs 0-31 and JSRs to them.  These 'INIT's are used to 
  251. set up the keyboard maps (INITs 0 and 1), install patches (of type PTCH) to ROM code, and so 
  252. on.  'INIT' 31 extends the system further by looking for any files of type INIT in the System 
  253. Folder.  This facility allows developers to install their own startup code without changing the 
  254. System file.  This could be another possible way to install yourself for debugging purposes.  An 
  255. 'INIT' resource in a file of type 'INIT' could be created with ResEdit to immediately drop into 
  256. MacsBug, for example.  The 'INIT' resource could simply be the hex string $A9FF 4E75.Then the 
  257. startup application is launched.  This is typically the Finder, but the startup application can be set to 
  258. any other application through the "Set Startup" menu item in the Finder.
  259.  
  260.  
  261. Using MacsBug
  262.  
  263.  
  264. The simplest way to get into MacsBug is to generate an exception by pressing the interrupt button. 
  265. (The interrupt button is the rear button of the programmer’s switch on Macintosh or the minus key 
  266. on the numeric keypad on Lisa).
  267.  
  268.  
  269. To see the application screen while the debugger is active, press the tilde/opening quote key (~/`) in 
  270. the upper-left corner of the keyboard.  Repeated presses toggle between the two screens, thus 
  271. allowing easy viewing of both the actual code (MacsBug screen) and the results (main screen).  To 
  272. restore the debugger’s display, press any character key.
  273.  
  274.  
  275. The best way to programmatically enter the debugger is to use the system trap called Debugger as a 
  276. breakpoint in your program at the point where you want MacsBug to get control.  There are two 
  277. ways to use this trap.  Calling trap $A9FF drops into MacsBug and displays the message 
  278. “USERBRK.”  It then does a normal exception entry into MacsBug (unless you have toggled the 
  279. DX command— see “Break Commands” below).  If you want to display custom debugging 
  280. information, declare and call the trap with bit 10 set ($ABFF) .  When this latter trap is 
  281. encountered, MacsBug assumes that the top of the user’s stack has a pointer to a Pascal string.  It 
  282. prints out the string, displays the message “USERBRK,” and does a normal exception entry into 
  283. MacsBug.
  284.  
  285.  
  286. Here is a summary of how to declare and use this trap from MDS Assembly Language:
  287.  
  288.  
  289.     Declaration
  290.  
  291.  
  292.     .TRAP    _Debugger     $A9FF     ; predefined in the file Traps.txt
  293.  
  294.     .TRAP    _DebugStr    $ABFF     ; not predefined - define it  yourself
  295.  
  296.     
  297.  
  298.     Example Calls
  299.  
  300.  
  301.     a)    _Debugger        ; enters MacsBug and displays USERBRK
  302.  
  303.  
  304.     b)    STRING PASCAL        ; asm directive to make sure to push a Pascal string
  305.  
  306.         PEA #'Entered main loop'    ; push address of string on stack
  307.  
  308.         _DebugStr        ; enters MacsBug and displays message
  309.  
  310.  
  311.  
  312. When MacsBug gets control, it disassembles the instruction indicated by the PC and displays the 
  313. contents of the registers.  If the exception was caused by a $A9FF or $ABFF instruction, MacsBug 
  314. displays the message “USERBRK”, advances the PC to the next instruction, and then disassembles 
  315. the instruction and displays the registers.  It then displays the greater-than symbol (>) as a prompt, 
  316. indicating that it is ready to accept a command.
  317.  
  318.  
  319. Two other ways are available for entering MacsBug:  FKEYs and INIT resources.  By using 
  320. ResEdit a skilled user can create a custom resource of either type whose sole function is described 
  321. by two simple 68000 instructions:  $A9FF $4E75 (_Debugger and RTS - the sequence to enter 
  322. MacsBug)  
  323.  
  324.  
  325. Note:  Another way to generate an exception that was popular in the past was to add a line such as 
  326.  
  327.  
  328.         DC.W    $FECE        ; generate a line 1111 exception
  329.  
  330.  
  331. at the point in your program where you wanted MacsBug to first get control.  (Any value $F000 
  332. through $FFFF could have been used.)  This method should not be used any more, as these 
  333. instructions have been reserved by Motorola for use in their coprocessor interface for their 68020 
  334. microprocessor.  (For example, in the future these “exceptions” could actually be MC 68881 floating 
  335. point instructions!)
  336.  
  337.  
  338.  
  339.  
  340. The MacsBug Command Language
  341.  
  342.  
  343. Commands consist of one or two command characters followed by a list of zero or more parameters 
  344. (depending on the command).  Parameters can be numbers, text literals, symbols, or simple 
  345. expressions.  
  346.  
  347.  
  348.  
  349. Numbers
  350.  
  351.  
  352. As is fitting for a debugger, all numbers are hex unless otherwise specified.  Decimal numbers are 
  353. preceeded by a pound sign (#).  Hexadecimal numbers can optionally be preceded by a dollar sign 
  354. ($).  Numbers can be signed (+ or –).  A hex word (4 hex characters) preceeded by a left angle (<) 
  355. is sign extended to a long word.  Here are some numbers in different formats—the formats shown 
  356. are the same as those displayed by the CV (Convert) command, described later in this chapter.
  357.  
  358.  
  359.     Number    Unsigned Hex    Signed Hex    Decimal
  360.  
  361.  
  362.     $FF    $000000FF    $000000FF    #255
  363.  
  364.     37    $00000037    $00000037    #55
  365.  
  366.     -FF    $FFFFFF01    -$000000FF    -#255
  367.  
  368.     #100    $00000064    $00000064    #100
  369.  
  370.     +10    $00000010    $00000010    #16
  371.  
  372.     #-32    $FFFFFFE0    -$00000020    #-100
  373.  
  374.       <FFFA    $FFFFFFFA    -$00000006    #-6
  375.  
  376.  
  377.  
  378. Strings
  379.  
  380.  
  381. A text literal is a one- to four-character ASCII string bracketed by single quotes (').  If a string is 
  382. longer than four characters, only the first four characters are used.  When used by MacsBug, text 
  383. literals are right justified in a long word.  Here are some examples:
  384.  
  385.  
  386.  
  387.     String    Stored as
  388.  
  389.      
  390.  
  391.     'A'    $00000041
  392.  
  393.     'Fred'    $46726564
  394.  
  395.     '1234'    $31323334
  396.  
  397.  
  398.  
  399.  
  400. Symbols
  401.  
  402.  
  403. These symbols are generally used to represent the registers:
  404.  
  405.  
  406.  
  407.         A0 through A7    Address registers A0 through A7
  408.  
  409.         D0 through D7    Data registers D0 through D7
  410.  
  411.         PC        Program counter
  412.  
  413.         .        Last address referenced (“Dot”)
  414.  
  415.         TP        Current QuickDraw port (thePort)
  416.  
  417.  
  418.  
  419.  
  420.  
  421. Expressions
  422.  
  423.  
  424. Expressions are formed by operators acting on numbers, text literals, and symbols.  
  425.  
  426. The operators are:
  427.  
  428.  
  429.  
  430.     +    addition (infix); assertion (prefix)
  431.  
  432.     -    subtraction (infix); negation (prefix)
  433.  
  434.     @ or *    indirection operator ( 2 different prefix operators with identical functionality)
  435.  
  436.     &    address operator (prefix)
  437.  
  438.     <    add sign extended # (infix); sign extension (prefix)
  439.  
  440.  
  441.  
  442. The indirection operator uses the long integer at the location pointed to by the operand.  Here are 
  443. some valid expressions:
  444.  
  445.  
  446.     RA7+4
  447.  
  448.     3A700-@10C
  449.  
  450.     TP+#24
  451.  
  452.     -RA0+RA1-'FRED'+@@4C50
  453.  
  454.     RA5<FE34        (Same as RA5+FFFFFE34 - useful in looking at global variables)
  455.  
  456.  
  457. Important:  Expressions are evaluated from left to right.  All operators are of equal precedence.  
  458. There is no way to alter the order of evaluation.
  459.  
  460.  
  461. Commands
  462.  
  463.  
  464. MacsBug commands can be divided into five groups:  memory, breaks, A-Traps, heap zone, and 
  465. disassembly.  A Return character repeats the last command entered, unless specified otherwise in 
  466. the descriptions below.  
  467.  
  468.  
  469. Parameters are represented by descriptive words and abbreviations such as address, number, and 
  470. expr.  All parameters can be entered as expressions.
  471.  
  472.  
  473.  
  474. General Commands
  475.  
  476.  
  477.     ?                 (Help)
  478.  
  479.  
  480.  
  481. Displays a short list of MacsBug commands and their parameters.
  482.  
  483.  
  484.  
  485.     DV            (Display Version)
  486.  
  487.  
  488. Displays the version, the date and time of creation, and signature of MacsBug.  For example,
  489.  
  490.         
  491.  
  492.     MACSBUG 5.1B1  17-May-86 00:05:10  <DKA> 
  493.  
  494.  
  495.  
  496.     RB            (Reboot)
  497.  
  498.  
  499.  
  500. Reboots the system.
  501.  
  502.  
  503.  
  504.     ES            (Exit to Shell)
  505.  
  506.  
  507.  
  508. Invokes the trap ExitToShell, which causes the current shell to be launched.  The current shell is 
  509. usually the Finder but can be changed by editing the boot blocks with FEdit.  The current shell 
  510. must reside in the System Folder and is logically different from the startup application.
  511.  
  512.  
  513.  
  514. Technical Note:  ES may not work with applications that override important system traps.  This is 
  515. because the application heap gets initialized promptly upon calling the trap ExitToShell which 
  516. usually trashes any system patches that used to be located there.  However, there is a hook 
  517. provided which is called by InitApplZone called IAZNotify that can be used to restore the world 
  518. before purging the otherwise necessary routines.
  519.  
  520.  
  521.  
  522.  
  523. EA            (Exit to Application)
  524.  
  525.  
  526.  
  527. Relaunches the application.  This is a faster method than calling ES and then relaunching from the 
  528. Finder.
  529.  
  530.  
  531.  
  532. Memory Commands
  533.  
  534.  
  535.  
  536.     CV      expr        (Convert)
  537.  
  538.  
  539.  
  540. Displays expr as unsigned hexadecimal, signed hexadecimal, signed decimal, text, and binary.
  541.  
  542.  
  543.  
  544.     DM  [ address   [ number ] ]    (Display Memory)
  545.  
  546.  
  547.  
  548. Displays number bytes of memory starting at address. 
  549.  
  550.  
  551.  
  552. Number is rounded up to the nearest 16 bytes.  If number is omitted, 16 bytes are displayed.  If 
  553. address and number are omitted, the next 16 bytes are displayed.  The dot symbol is set to the 
  554. address of the beginning of the last block displayed.
  555.  
  556.  
  557.  
  558. If number is set to certain four-character strings, memory is instead symbolically displayed as a 
  559. data structure that begins at address.  Refer to Inside Macintosh for a description of these data 
  560. structures.  The strings and the data structures they represent are
  561.  
  562.  
  563.     'IOPB'    Input/Output Parameter Block for File I/O
  564.  
  565.     'WIND'    Window Record
  566.  
  567.     'TERC'    TextEdit Record
  568.  
  569.  
  570. You can usually terminate a 'DM' command by pressing the Backspace key.
  571.  
  572.  
  573.  
  574.  
  575.  
  576.     SM  address  exp..    .    (Set Memory)
  577.  
  578.  
  579. Places the specified values, expr1 through exprN, into memory starting at address.  The size of 
  580. each value depends on the “width” of each expression.  The width of a decimal or hexadecimal 
  581. value is the smallest number of bytes that holds the specified value (four-byte maximum).  Text 
  582. literals are from one to four bytes long; extra characters are ignored.  Indirect values are always 
  583. four bytes long.  The width of an expression is equal to the width of the widest of its operands.  
  584. The dot symbol is set to address .
  585.  
  586.  
  587.     Dn  [ expr ]            (Data Register)
  588.  
  589.  
  590.  
  591. Displays or sets data register n.  If expr is omitted, the register is displayed.  Otherwise, the register 
  592. is set to expr.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598.     An  [ expr ]            (Address Register)
  599.  
  600.  
  601.  
  602. Displays or sets address register n.  If expr is omitted, the register is displayed.  Otherwise, the 
  603. register is set to expr.
  604.  
  605.     PC  [ expr ]            (Program Counter)
  606.  
  607.  
  608.  
  609. Displays or sets the program counter.  If expr is omitted, the program counter is displayed.  
  610. Otherwise, the PC is set to expr.
  611.  
  612.  
  613.  
  614.  
  615.  
  616.     SR  [ expr ]            (Status Register)
  617.  
  618.  
  619.  
  620. Displays or sets the status register.  If expr is omitted, the status register is displayed.  Otherwise 
  621. the status register is set.
  622.  
  623.  
  624.  
  625.  
  626.  
  627.     TD            (Total Display)
  628.  
  629.  
  630.  
  631. Displays all of the 68000 registers and the PC, and disassembles the current instruction that is 
  632. about to be executed upon stepping, tracing, or going.
  633.  
  634.  
  635.  
  636.  
  637.     RX            (Register Exchange)
  638.  
  639.  
  640.  
  641. Toggles the display mode so that the registers are or are not dumped during a trace command.  The 
  642. disassembly of the PC instruction is not affected.
  643.  
  644.  
  645.  
  646.     CS  [ address1  [address2 ] ]    (Checksum)
  647.  
  648.  
  649.  
  650. Checksums the bytes in the range address1 through address2 and saves that value.  The checksum 
  651. is an exclusive OR of the bytes in the range specified.  If address2 is omitted, it checksums 16 
  652. bytes, starting at address1.  If address1 and address2 are both omitted, it calculates the checksum 
  653. for the last range specified, saves that value, and compares it to the previous checksum for that 
  654. range.  If the checksum hasn’t changed, it prints “CHKSUM T”; otherwise it prints “CHKSUM 
  655. F”.
  656.  
  657.  
  658.  
  659. Break Commands
  660.  
  661.  
  662.  
  663.     BR  [ address  [ count ] ]    (Break)
  664.  
  665.  
  666.  
  667. Sets a breakpoint at address.  Count specifies the number of times that the breakpoint should be 
  668. executed before stopping the program.  If count is omitted, the program is stopped the first time the 
  669. breakpoint is hit.  If address is omitted, all breakpoints are displayed.  You can set a maximum of 8 
  670. different breakpoints.
  671.  
  672.  
  673.  
  674.     CL  [ address ]        (Clear)
  675.  
  676.  
  677.  
  678. Clears the breakpoint at address.  If address is omitted, all breakpoints are cleared.
  679.  
  680.   
  681.  
  682.     G  [ address ]        (Go)
  683.  
  684.  
  685.  
  686. Executes instructions starting at address.  If address is omitted, execution begins at the address 
  687. indicated by the program counter.  Control does not return to MacsBug until an exception occurs.
  688.  
  689.  
  690.  
  691.     GT  address    (Go Till)
  692.  
  693.  
  694.  
  695. Sets a one-time breakpoint at address, then executes instructions starting at the address indicated by 
  696. the program counter.  This breakpoint is automatically cleared after it is hit.  (GT address is 
  697. equivalent to a BR address and G with the BR being cleared after the first time it is hit.)
  698.  
  699.  
  700.  
  701.  
  702.  
  703.     T            (Trace)
  704.  
  705.  
  706.  
  707. Traces through one instruction.  Traps are treated as single instructions.  If the next instruction to 
  708. be executed is a JSR to a currently unloaded segment, you will see instead of the JSR the LoadSeg 
  709. ($A9F0) trap.  Tracing through that instruction will not work normally.  If you wish to trace 
  710. through the LoadSeg trap a low memory global needs to be set to a non-zero value.  That location is 
  711. $12D.  Do a SM 12D 1 to enable tracing through the LoadSeg call.  Next, Go (G).  You will break 
  712. at an RTS instruction.  Trace once (T) to see the absolute location that you are about to jump to.  
  713. Trace again and you will be at the first step of the routine that now is loaded into memory.
  714.  
  715.  
  716.  
  717.  
  718.  
  719. S  [number ]            (Step)
  720.  
  721.  
  722.  
  723. Steps through number instructions.  If number is omitted, just one instruction is executed.  Traps 
  724. are not considered to be single instructions.
  725.  
  726.  
  727.  
  728.  
  729.  
  730. SS  [address1  [ address2 ] ]    (Step Spy)
  731.  
  732.  
  733.  
  734. Calculates a checksum for the specified memory range, then does a Go; it then checks the 
  735. checksum before each 68xxx instruction is executed, and breaks into MacsBug if the checksum 
  736. doesn’t match.  If address1 and address2 are omitted, this feature is turned off.
  737.  
  738.  
  739. Step Spy is very slow.  Step Spy is nevertheless useful for detecting what routines are stepping on 
  740. a specific place in memory.  If checking memory every A-trap is sufficient for your needs, use the 
  741. AS command, described below.  (The slow motion capability of SS, however, can be useful in its 
  742. own right to examine how the Finder zooms windows, for example.  Think of it as a tool to study 
  743. graphics algorithms.)
  744.  
  745.  
  746.  
  747.  
  748.  
  749.     ST  address            (Step Till)
  750.  
  751.  
  752.  
  753. Steps through instructions until address is encountered.  Unlike Go Till, this command does not set 
  754. a breakpoint.  Thus it can be used to step through, and stop in, ROM.
  755.  
  756.  
  757.  
  758.  
  759.  
  760.     MR  [ offset ]        (Magic Return)
  761.  
  762.  
  763.  
  764.     MR functions according to this formula:
  765.  
  766.  
  767.     IF offset > A6 THEN magic = offset + 4 ELSE magic = A7 + offset 
  768.  
  769.  
  770. The default offset  is 0. This allows you to type MR RA6 when in nested subroutine calls. The 
  771. usual way to use this routine is to trace until just after a JSR (return address 0 bytes down in the 
  772. stack), and then do an MR.  The rest of the routine is executed, and control returns to MacsBug.  
  773. This command isn’t repeated when you press Return; a Trace command is executed instead.
  774.  
  775.  
  776. When debugging, you generally trace through a program one instruction at a time.  MR lets you 
  777. trace through to the end of a routine instead.  When you use MR, it replaces the return address that 
  778. is offset bytes down in the stack with an address within MacsBug; then it does a Go (described 
  779. above).  The RTS that would have used that address returns to MacsBug instead of to the caller.  
  780. MacsBug restores the original return address, and then executes the RTS as if called by the Trace 
  781. command.  The prompt is then displayed, ready to trace the instruction after RTS.
  782.  
  783.  
  784.  
  785.  
  786.  
  787.  
  788. DX            (Debugger Exchange)
  789.  
  790.  
  791. Normally, if either the $A9FF or the $ABFF A-trap (two forms of the Debugger trap) is executed, 
  792. program execution halts and the debugger is activated.  DX allows you to control whether or not 
  793. program execution halts.  Note that the $ABFF trap will still print a string; thus with debugger 
  794. entry disabled an effect similar to that of the AT command occurs—that is, the Macintosh screen 
  795. alternates between the debugger and the program.  The default is to stop at Debugger traps.
  796.  
  797.  
  798.  
  799.  
  800.  
  801. A-Trap Commands
  802.  
  803.  
  804. The A-Trap commands are used to monitor “1010 emulator” traps, used to call the Macintosh 
  805. ROM.  These commands use up to six parameters (trap1, trap2, address1, address2, D1, and D2).  
  806. These parameters indicate which traps and other conditions should be monitored:  
  807.  
  808.  
  809. •    Trap1 and trap2  specify the range of the traps.  Operating System traps are in the range 
  810. $A000 and $A0FF; Toolbox traps are between $A800 and $A9FF.  Numbers in the range 0 to $6F 
  811. are shortcut expressions for OS traps.  Numbers greater than or equal to $70 are interpreted as 
  812. Toolbox traps.  If only trap1 is specified, the command is invoked for trap1.  If trap1 and trap2 are 
  813. specified, the command is invoked for all traps in the range trap1 through trap2.  The defaults are 
  814. $A000 and $AA00.
  815.  
  816.  
  817. •    Address1 and address2 specify a range of memory addresses within which traps should be 
  818. monitored.  The defaults are 0 and $FFFFFFFF.
  819.  
  820.  
  821. •    D1 and D2  specify the values of data register 0 within which traps should be monitored. 
  822. They are treated as unsigned numbers.  The defaults are 0 and $FFFFFFFF. 
  823.  
  824.  
  825. Thus if no parameters are given, all traps are monitored.  
  826.  
  827.  
  828. Unlike break commands, only one A-trap break command and one A-trap trace command can be 
  829. active at the same time.  In addition,  the A-trap command with the “wider” range of traps must be 
  830. executed last.  For example, if you wished to view (trace) all file system traps called from your 
  831. application but also wanted to stop at the next Open command, you could type the following 
  832. commands:
  833.  
  834.  
  835.     BA     Open
  836.  
  837.     AA     0 17        (shorthand for file system traps)
  838.  
  839.  
  840. If you typed them in the reverse order you would not see any of the tracing because the smaller 
  841. ranged command was executed last.  In general, the parameters most recently given are the ones 
  842. used; it is only the A-trap range that can be remembered for two different A-trap commands.
  843.  
  844.  
  845. You generally use the Go command immediately after a trap command to await the use of a 
  846. specified trap.  When a trap in the indicated range is encountered, appropriate information is 
  847. displayed.  Displayed trap numbers are given in full word format ($Axxx).
  848.  
  849.  
  850.  
  851. BA  [ trap1  [ trap2  [ address1  [address2  [ D1  [D2] ] ] ] ] ]    (Break in Application)
  852.  
  853.  
  854.  
  855. Causes a break when the conditions specified by the parameters are satisfied and the trap is being 
  856. called from the application rather than from the ROM.  Address1  and address2 are automically set 
  857. to ApplZone and BufPtr.  Therefore this command can be used to get back to the application when 
  858. in ROM.  Simply type BA and Go.  MacsBug will be entered at the next trap called by code located 
  859. in the application heap.  To break on ROM calls as well ( or traps called from the System Heap or 
  860. elsewhere) use AB which is described below.
  861.  
  862.  
  863.  
  864.  
  865.  
  866. AA  [ trap1  [ trap2  [ address1  [address2  [ D1  [D2] ] ] ] ] ]    (Application A-Trap         
  867.             Trace)
  868.  
  869.  
  870.  
  871. Traces and displays each A-Trap called from the application heap without breaking if the conditions 
  872. specified by the parameters are satisfied.  This command continues to display A-Traps until you 
  873. press the interrupt button.  This allows you to monitor just the traps that the application calls, and 
  874. thus can be useful for checking and measuring performance.  To monitor all traps called, including 
  875. calls made from inside the ROM and traps called from the System Heap, use the AT command.
  876.  
  877.  
  878.  
  879.  
  880.  
  881.  
  882. AB  [ trap1  [ trap2  [ address1  [address2  [ D1  [D2] ] ] ] ] ]    (A-Trap Break)
  883.  
  884.  
  885.  
  886. Causes a break when the conditions specified by the parameters are satisfied.  AB without any 
  887. parameters will thus stop at the very next trap executed anywhere by Macintosh.  To stop at the next 
  888. trap called by the current application, use BA instead.
  889.  
  890.  
  891.  
  892.  
  893.  
  894. AT  [ trap1  [ trap2  [ address1  [address2  [ D1  [D2] ] ] ] ] ]    (A-Trap Trace)
  895.  
  896.  
  897.  
  898. Traces and displays each A-Trap without breaking, when the condition specified by the parameters 
  899. is satisfied.  This command continues to display all A-Traps until you press the interrupt button.  If 
  900. you wish to just see the traps called by the current application, use AA instead.
  901.  
  902.  
  903. For example, to see all QuickDraw calls displayed, regardless of who calls them, one could type         
  904.  
  905.     AT A86C A8FB
  906.  
  907.  
  908.  
  909.  
  910.  
  911. AH  [ trap1  [ trap2  [ address1  [address2  [ D1  [D2] ] ] ] ] ]    (A-Trap Heap Zone     
  912.                 Check)
  913.  
  914.  
  915.  
  916. Checks the heap zone for consistency just before executing each trap in the specified range.  If an 
  917. inconsistency is found, it displays the addresses of the two memory blocks in question.
  918.  
  919.  
  920.  
  921. AR  [ trap1  [ trap2  [ address1  [address2  [ D1  [D2] ] ] ] ] ]    (A-Trap Record)
  922.  
  923.  
  924. Whenever the parameter constraints are satisfied by an A-trap call, information about the call is 
  925. recorded.  The trap name, PC, A0, D0, and time are always saved.  If the call was for an OS trap, 
  926. 32 bytes pointed at by A0 are recorded; otherwise 32 bytes pointed at by A7 (stack ptr) are saved.  
  927. To display the current saved information, type AR with no arguments.
  928.  
  929.  
  930. This command is especially useful for tracking down crashes in the Macintosh ROM.  For 
  931. example,
  932.  
  933.  
  934.     >AR 0 1000 @2AA @114
  935.  
  936.  
  937. records traps 0 through 1000 (all traps) from ApplZone ($2AA) through HeapEnd ($114), so it will 
  938. record the last trap call made from anywhere in the application heap (the application’s code).
  939.  
  940.  
  941.     AS address1  [address2  ]        (A-Trap Spy)
  942.  
  943.  
  944.  
  945. Calculates a checksum for the specified memory range, and then checks it before each and every A-
  946. trap that is called.  Breaks into MacsBug if the checksum does not match.  Use SS if you want the 
  947. range of memory to be checked before every 68xxx instruction rather than just before every A-trap.
  948.  
  949.  
  950.  
  951.  
  952.  
  953.     AX                (A-Trap Clear)              
  954.  
  955.      Clears all A-Trap commands.
  956.  
  957.  
  958.  
  959.  
  960.  
  961. Heap Zone Commands
  962.  
  963.  
  964. The heap zone commands act upon the current heap zone.  When MacsBug is started up, the 
  965. current heap zone is the application heap zone.  You can set the current heap zone by using the HX 
  966. command.  Several commands cause MacsBug to scramble the heap zone.  When MacsBug 
  967. scrambles the heap zone, it rearranges all the relocatable blocks.  This is useful for finding illegally 
  968. used pointers to relocatable data structures.
  969.  
  970.  
  971.  
  972.  
  973. HX  [ address ]            (Heap Exchange)
  974.  
  975.  
  976.  
  977. Sets the current heap to address.  If no address  is given, then HX toggles the current heap zone 
  978. between the system heap zone and the application heap zone.  In any case, HX displays the 
  979. resulting current heap address.
  980.  
  981.  
  982.  
  983.  
  984.  
  985. HC                    (Heap Check)
  986.  
  987.  
  988.  
  989. Checks the consistency of the current heap zone, and displays the addresses of inconsistent 
  990. memory blocks as well as the address of the current heap.
  991.  
  992.  
  993.  
  994.  
  995.  
  996. HS  [ trap1  trap2 ]            (Heap Scramble)
  997.  
  998.  
  999.  
  1000. Scrambles the heap zone, by moving relocatable blocks, when certain traps in the specified range 
  1001. are encountered.  It always scrambles the heap zone as a result of NewPtr, NewHandle, and 
  1002. ReallocHandle calls.  It scrambles the heap zone as a result of SetHandleSize and SetPtrSize if the 
  1003. new length is greater than the current length.  This command is fastest if you set trap1 to $18 and 
  1004. trap2 to $2D.  The heap zone is not scrambled as a result of traps other than those named above.
  1005.  
  1006.  
  1007. HD [ mask ]                (Heap Dump)
  1008.  
  1009.  
  1010.  
  1011. Mask is optional.  Whether or not mask is used, it displays each block in the current heap zone in 
  1012. the following form:
  1013.  
  1014.  
  1015.  
  1016. blockAddr    type    size    [ flag   MP_location ]    [ * ]    [ refNum   ID   type ]
  1017.  
  1018.  
  1019.  
  1020.     •    The blockAddr points to the start of the memory block.  
  1021.  
  1022.  
  1023.     •    The type is one of the following letters:
  1024.  
  1025.  
  1026.         F     free block
  1027.  
  1028.         P    pointer
  1029.  
  1030.         H    handle to a relocatable block  
  1031.  
  1032.  
  1033. •    The size is the physical size of the block, including the contents, the header, and any unused 
  1034. bytes at the end of the block.  
  1035.  
  1036.  
  1037. •    For handles (type H), flag  is either blank if not purgable or a ‘P’ if purgable.  Then   
  1038. MP_location  is displayed, which is the address of the master pointer to the relocatable block.
  1039.  
  1040.  
  1041. •    The asterisk marks any locked object (nonrelocatable blocks and locked relocatable blocks).
  1042.  
  1043.  
  1044. •    For resource file blocks, three additional fields are displayed:  the resource’s reference 
  1045. number, ID number, and type.  If mask is omitted, the dump is followed by a summary of the heap 
  1046. zone’s blocks.  It begins with the six characters “HLP  PF”, which represent the six values that 
  1047. follow them.  These values are  
  1048.  
  1049.  
  1050.             H    number of relocatable blocks in the heap zone (Handles)
  1051.  
  1052.             L    number of relocatable blocks that are Locked
  1053.  
  1054.             P    number of Purgeable blocks in the heap zone
  1055.  
  1056.             (space)    space, in bytes, occupied by purgeable blocks
  1057.  
  1058.             P    number of nonrelocatable blocks in the heap zone (Pointers)
  1059.  
  1060.             F    total amount of Free space in the heap zone
  1061.  
  1062.  
  1063.  
  1064. Here is a sample summary:
  1065.  
  1066.  
  1067.  
  1068. HLP PF 0084  0004  0002  0000079E  0017  000003B4
  1069.  
  1070.  
  1071.  
  1072. Note that block counts are single words, and values representing space in bytes are long word 
  1073. quantities.  If mask is used, the summary line displays the block counts of specific types of blocks.  
  1074. Possible values for mask are
  1075.  
  1076.  
  1077.  
  1078.             'H'    Relocatable blocks (handles)
  1079.  
  1080.             'P'    Nonrelocatable blocks (pointers)
  1081.  
  1082.             'F'    Free blocks
  1083.  
  1084.             'R'    Resource blocks
  1085.  
  1086.             'xxxx'    Resource blocks of type 'xxxx'
  1087.  
  1088.  
  1089.  
  1090. If mask is used, the heap summary takes this form:
  1091.  
  1092.  
  1093.  
  1094. CNT ###  <# of blocks of mask type>  <# bytes in those blocks>
  1095.  
  1096.  
  1097.  
  1098. You can prematurely terminate an HD command by pressing the Backspace key.  
  1099.  
  1100. The dot address is set to the last block of memory displayed by HD.
  1101.  
  1102.  
  1103.  
  1104. HT  [ mask ]                (Heap Total)
  1105.  
  1106.  
  1107.  
  1108. Displays just the summary line from a heap zone dump.  Mask works just as it does with the HD 
  1109. command (described above).
  1110.  
  1111.  
  1112.  
  1113.  
  1114. SC                    (Stack Crawl)
  1115.  
  1116.  
  1117. Assumes that LINK / UNLK A6 has been religiously performed at the beginning and end of each 
  1118. procedure or function.  (Use the $D+ option in Pascal, the -g and -ga options in C)  The output 
  1119. format is as follows:
  1120.  
  1121.  
  1122.     SF    @<stack frame location>      <address of call to procedure>
  1123.  
  1124.  
  1125. For example,
  1126.  
  1127.  
  1128.     SF @0D633C  ProcName+3A
  1129.  
  1130.  
  1131. means that the currently executing procedure or function has its local stack frame at $D633C and 
  1132. was called from ProcName+$3A (which is not the return address!).  As the ROM does not use 
  1133. LINK / UNLK consistently (due to space & time considerations), SC does not work when in ROM 
  1134. routines. 
  1135.  
  1136.  
  1137.  
  1138.  
  1139. Disassembler Commands
  1140.  
  1141.  
  1142. SD  [ address ]                (Symbol Dump)
  1143.  
  1144.  
  1145. Displays a list of the procedure names that can be found in the current heap zone.  The search 
  1146. criteria is based on looking in blocks of memory whose locked bit is set.  In addition, a LINK A6 
  1147. and its matching UNLK A6 must be found, followed by either a JMP (A0) or a RTS.  The eight 
  1148. character debugging name follows.  Valid debug symbols must have characters between an ASCII 
  1149. space ($20) and the underscore character ($5F) inclusive.  This command optionally allows you to 
  1150. specify a starting location for the symbol dump.
  1151.  
  1152.  
  1153. PX                    (Symbol Toggle)
  1154.  
  1155.  
  1156.  
  1157. Determines whether or not symbols are displayed.  By default, symbols are turned on.  This 
  1158. command affects any command that takes an address.  Using symbols allows you to IL or BR on a 
  1159. procedure name.  For example,
  1160.  
  1161.  
  1162.     >IL ProcName+58
  1163.  
  1164.  
  1165. will disassemble code starting at 58 bytes (hex) into the procedure called ProcName, and
  1166.  
  1167.  
  1168.     >BR ProcName+58
  1169.  
  1170.  
  1171. will set a breakpoint at the same location (this also works for GT, ST, DM, and so on.).  
  1172.  
  1173.  
  1174. Note that your code must be created with the symbols embedded in the code in order for this to 
  1175. work.
  1176.  
  1177.  
  1178. DH  number                 (Disassemble Hex)
  1179.  
  1180.  
  1181. Disassembles the hex byte, word, or long word input.  Typing just one byte allows you to see the 
  1182. general class of instructions, as number is left aligned in a long word padded to the right with 
  1183. zeros.  (Typing DH 10, DH 20, and DH 30, for example, show by induction that these instruction 
  1184. groups are the Move.B, Move.W, and Move.L classes, respectively.)
  1185.  
  1186.  
  1187. This command is useful as a poor man's assembler:  guess an opcode and use this command to see 
  1188. if it is what you want.  Example:  was reset $4E71?  Type DH 4E71 and see NOP.  Try DH 4E70 
  1189. and see RESET.
  1190.  
  1191.  
  1192. ID  [ address ]                (Instruction             
  1193.         Disassemble)
  1194.  
  1195.  
  1196.  
  1197. Disassembles one line at address.  If address is omitted, the next logical location is disassembled.  
  1198. ID sets the dot symbol to the address.
  1199.  
  1200.  
  1201.  
  1202. If the code has symbols compiled in with it, and symbols have been turned on with the PX 
  1203. command, each address is automatically displayed as a routine name plus an offset.
  1204.  
  1205.   
  1206.  
  1207. IL  [ address  [ number ] ]        (Instruction List)
  1208.  
  1209.  
  1210.  
  1211. Disassembles number lines starting at address.  If number is omitted, a screenful of lines (typically 
  1212. 16) is disassembled.  If both number and address are omitted, a screenful of lines is disassembled 
  1213. starting at the next logical location.  This command sets the dot symbol to the address.
  1214.  
  1215.  
  1216. If the code has symbols compiled in with it, and symbols have been turned on with the PX 
  1217. command, each address is automatically displayed as a routine name plus an offset.
  1218.  
  1219.  
  1220. You can prematurely terminate an IL command by pressing the Backspace key.  
  1221.  
  1222. F  address   count   data   [ mask  ]        (Find)
  1223.  
  1224.  
  1225.  
  1226. Searches count bytes from address, looking for data after masking the target with mask.  As soon 
  1227. as a match is found, the address and value are displayed, and the dot symbol is set to that address.  
  1228. To search the next count bytes, simply press Return.  The size of the target is determined by the 
  1229. width of data.  It is limited to 1, 2, or 4 bytes.
  1230.  
  1231.  
  1232. For example, to find a RESET instruction in a program loaded into a 1 MB machine, you could 
  1233. type
  1234.  
  1235.  
  1236.     >F CB00 EFFFF 4E70
  1237.  
  1238.  
  1239. where CB00 is the beginning of the application heap on a Macintosh Plus, EFFFF represents the 
  1240. length of the application heap (roughly), and 4E70 is the RESET instruction.
  1241.  
  1242.  
  1243.  
  1244.  
  1245. WH  expr                (Where)
  1246.  
  1247.  
  1248.  
  1249. Where takes an expression, which can be a symbolic name.  It displays the location of the first 
  1250. routine that it finds whose name matches.  ROM symbol names are ten character names, while 
  1251. RAM symbols are eight character names.
  1252.  
  1253.  
  1254. If expr is less than $AA00, this command displays the address corresponding to the trap with that 
  1255. number.  All of the following commented commands, for example, give the same result:
  1256.  
  1257.  
  1258.     >WH    EXITTOSHELL    ; full name
  1259.  
  1260.     >WH    A9F4        ; full trap word
  1261.  
  1262.     >WH    1F4        ; shortcut 
  1263.  
  1264.     >WH    40F6D8    ; address of ExitToShell in the 128KB ROM
  1265.  
  1266.  
  1267. Namely,
  1268.  
  1269.  
  1270.     Trap Word    Address    Name
  1271.  
  1272.  
  1273.     A9F4        40F6D8     EXITTOSHELL
  1274.  
  1275.  
  1276. The shortcut method of inputting trap numbers interprets $0-$6F as OS traps and all other traps as 
  1277. Toolbox traps.
  1278.  
  1279.  
  1280. If expr is preceeded by the address operator (&) then the expression is forced to be evaluated as an 
  1281. address.  This is useful for examining system patches whose addresses are oftentimes less than 
  1282. $AA00, the default address boundary.
  1283.  
  1284.  
  1285.  
  1286. If expr is greater than or equal to $AA00 and less than RomBase, then the address is interpreted as 
  1287. a user routine in RAM, and a symbolic location will be displayed if possible.
  1288.  
  1289.  
  1290. If expr is in ROM then the trap whose code is closest to that address is displayed.  
  1291.  
  1292.  
  1293. This function is useful for finding out where you were when an error occurred.  If the address 
  1294. expression is in RAM and the WH function returns “PRGM AT $$$$” you can then use the HD 
  1295. 'CODE' command to list the code segments.  Then by comparing the locations of CODE segments 
  1296. and the current PC you can determine which segment you are in. 
  1297.  
  1298.